﻿@*YoursLC有源低代码 CreateTime:2022-04-04 11:38:07 添加或编辑-此文件放置于Views/Demo05/中*@

@using Think9.Models;
@model Think9.Models.Demo05Model
@{ ViewBag.Title = "Add";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

@*Demo05数据规则*@

<form class="layui-form" lay-filter="formUser">
<input style="display:none" id="_userid" value="@ViewBag.userid">@*用户id*@
<input style="display:none" id="_attachmentId">@*附件id*@
<input style="display:none" id="_type" value="@ViewBag.type">@*add或edit*@
<input style="display:none" id="prc_fid" value="@ViewBag.fid">@*当前流程编码*@
<input style="display:none" id="prc_id"  value="@ViewBag.prcid">@*当前流程步骤id*@
<input style="display:none" id="prc_no"  value="@ViewBag.prcno">@*当前流程步骤编码*@
<input style="display:none" id="sys_plit" value="@ViewBag.split">@*多选框字符分割*@
<input style="display:none" id="sys_listid" value="@ViewBag.listid">
<input style="display:none" id="Pu_value">
<input style="display:none" id="Pu_tbid">
<input style="display:none" id="Pu_indexid">
<input style="display:none" id="Pu_id">
<input style="display:none" id="Pu_v">
<div class="layui-form">
 <div class="layui-form-item"  style="text-align: right;">
	<div class="layui-btn-group">
			<button type="button" class="layui-btn" id="sys_att">附件</button>
			<button type="button" class="layui-btn" lay-submit lay-filter="edit">保存</button>
			<button type="button" class="layui-btn" lay-submit lay-filter="next">转交</button>
			@*<button type="button" class="layui-btn" lay-submit lay-filter="finish">结束</button>*@
	 </div>
  </div>

	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">自动编号</label>
			<div class="layui-input-block">
				<input type='text' name='inAutoNumber' id='inAutoNumber' autocomplete='off' class='layui-input'  maxlength='30'    placeholder='自动编号'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">日期选择</label>
			<div class="layui-input-block">
				<input  name='inDateSelection' id='inDateSelection'  class='layui-input' autocomplete='off'  onClick="WdatePicker({ el: this,dateFmt: 'yyyy-MM-dd'})" placeholder='日期选择'   lay-verify='date' >
			</div>
		</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
				<input type='text' name='inName' id='inName' autocomplete='off' class='layui-input'  maxlength='100'    placeholder='名称'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">弹出选择树</label>
			<div class="layui-input-block">
				<input type='text' name='inPopUpSelectionTree' id='inPopUpSelectionTree' autocomplete='off' class='layui-input'  maxlength='30'    placeholder='弹出选择树'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">弹出选择多列</label>
			<div class="layui-input-block">
				<input type='text' name='inPopUpSelectMultipleColumns' id='inPopUpSelectMultipleColumns' autocomplete='off' class='layui-input'  maxlength='30'    placeholder='弹出选择多列'>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">弹出选择单列</label>
			<div class="layui-input-block">
				<input type='text' name='inPopUpSelectSingleColumn' id='inPopUpSelectSingleColumn' autocomplete='off' class='layui-input'  maxlength='30'    placeholder='弹出选择单列'>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">下拉选择</label>
			<div class="layui-input-block">
				<select id="inXLXZ" name="inXLXZ"  lay-filter = "inXLXZ"  >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inXLXZ"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">下拉选择树</label>
			<div class="layui-input-block">
				<select id="inXLXZS" name="inXLXZS"  lay-filter = "inXLXZS"  >
					<option value="">==请选择==</option>
						@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inXLXZS"))
						{
							 <option value="@item.Value">@item.Text</option>
						}
				</select>
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">单选</label>
			<div class="layui-input-block">
				@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inSingleChoice"))
				{
					<input type="radio"  name="@item.ClassID" value="@item.Value" title="@item.Text">
				}
				</div>
			</div>
		<div class="layui-col-md6">
			<label class="layui-form-label">多选</label>
			<div class="layui-input-block">
				<input style="display: none" id="inMultipleChoice_Exa" name="inMultipleChoice_Exa" >
				@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inMultipleChoice"))
				{
					<input type="checkbox"  name="@item.ClassID" value="@item.Value" title="@item.Text" lay-filter = "inMultipleChoice"  lay-skin="primary">
				}
				</div>
			</div>
	 </div>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<label class="layui-form-label">弹出多选</label>
			<div class="layui-input-block">
				 <textarea class='layui-textarea' id='inPopUpMultipleSelections' name='inPopUpMultipleSelections'     placeholder='弹出多选'></textarea>
				</div>
			</div>
	 </div>
</div>

</form>
<script>
	layui.config({
		base: '/self_js/'  /*自定义的js文件 位于wwwroot/self_js文件夹中*/
	});
	layui.use(["form", "exLayer", "exUtils",  "table", "Demo05"], function () {
		let form = layui.form;
		let layer = layui.layer;
		let table = layui.table;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let mySelf = layui.Demo05;

		let $ = layui.$;
		form.render();

		getFormVal();//设置多选框和图片的显示--无多选框和图片可删除

		//根据步骤编码设置控件disabled
		mySelf.setStateByFlow($('#prc_no').val());
		//赋值--不包括多选框和图片
		form.val("formUser", {
			"inAutoNumber": "@Model.inAutoNumber"
			,"inDateSelection": showDate("@Model.inDateSelection")
			,"inName": "@Model.inName"
			,"inPopUpSelectionTree": "@Model.inPopUpSelectionTree"
			,"inPopUpSelectMultipleColumns": "@Model.inPopUpSelectMultipleColumns"
			,"inPopUpSelectSingleColumn": "@Model.inPopUpSelectSingleColumn"
			,"inXLXZ": "@Model.inXLXZ"
			,"inXLXZS": "@Model.inXLXZS"
			,"inSingleChoice": "@Model.inSingleChoice"
			,"inPopUpMultipleSelections": "@Model.inPopUpMultipleSelections"
		});
		//设置多选框和图片的显示
		function getFormVal() {
			//复选框 多选
			$('#inMultipleChoice_Exa').val('@Model.inMultipleChoice');
			 $('input[name=inMultipleChoice]').each(function () {
				if ($('#inMultipleChoice_Exa').val().indexOf($('#sys_plit').val() + $(this).val() + $('#sys_plit').val()) != -1) {
					$(this).attr('checked', true);
				}
			});


		}

		$('#inPopUpSelectionTree').on('click', function () {
			exLayer.open('选择弹出选择树', '/Demo05/PopUpSelectValue?tbid=_main&indexid=inPopUpSelectionTree&id=_n&from=add', '100%', '100%', '0px', '0px', null, null);
		});
		$('#inPopUpSelectMultipleColumns').on('click', function () {
			exLayer.open('选择弹出选择多列', '/Demo05/PopUpSelectValue?tbid=_main&indexid=inPopUpSelectMultipleColumns&id=_n&from=add', '100%', '100%', '0px', '0px', null, null);
		});
		$('#inPopUpSelectSingleColumn').on('click', function () {
			exLayer.open('选择弹出选择单列', '/Demo05/PopUpSelectValue?tbid=_main&indexid=inPopUpSelectSingleColumn&id=_n&from=add', '100%', '100%', '0px', '0px', null, null);
		});
		$('#inPopUpMultipleSelections').on('click', function () {
			exLayer.open('选择弹出多选', '/Demo05/PopUpSelectValue?tbid=_main&indexid=inPopUpMultipleSelections&id=_n&from=add', '100%', '100%', '0px', '0px', null, null);
		});

		//复选框 多选
		form.on('checkbox(inMultipleChoice)', function (data) {
			var arr_inMultipleChoice = [];
			$('input[name=inMultipleChoice]:checked').each(function () {
			arr_inMultipleChoice.push($(this).val());
			});
			var _inMultipleChoice = $('#sys_plit').val();
			for (const elem of arr_inMultipleChoice) {
				_inMultipleChoice = _inMultipleChoice + elem + $('#sys_plit').val();
			}
			if (_inMultipleChoice == $('#sys_plit').val()) {
				_inMultipleChoice = '';
			}
			$('#inMultipleChoice_Exa').val(_inMultipleChoice);
			return false;
		});


		$('#sys_att').on('click', function () {
			exLayer.open('附件上传', '/Com/FileManage/Attachment?fwid=' + $('#prc_fid').val() + '&listid=' + $('#sys_listid').val() + '&prcid=' + $('#prc_id').val() + '&userid=' + $('#_userid').val() + '&attid=' + $('#_attachmentId').val(), '100%', '100%', '0px', '0px', null, null);
		});
		//点击保存按钮
		form.on("submit(edit)", function (data) {
			var _gridList = [];
			mySelf.foreachGridTable(_gridList);//遍历子表table取数
			exUtils.ajax('/Demo05/SaveData', 'post', {
				model: data.field, 'gridlist': _gridList, listid: $('#sys_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val() }, true).done(function (response) {
				exLayer.greenTickMsg(response.message, function () {
				$(window.parent.document).find('#search').click();
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			});
		}).fail(function (error) {
			console.log(error);
		});
			return false;
		});
		//点击转交按钮
		form.on('submit(next)', function (data) {
			var _gridList = [];
			mySelf.foreachGridTable(_gridList);
			exUtils.ajax('/Demo05/NextStep', 'post', { model: data.field, 'gridlist': _gridList, listid: $('#sys_listid').val(), prcno: $('#prc_no').val(), type: $('#_type').val(), att: $('#_attachmentId').val() }, true).done(function (response) {
				$('#sys_listid').val(response.extra);
				exLayer.open('流程转交', '/SysFlow/PrcsNext/Next?listid=' + response.extra + '&flid=' + $('#prc_fid').val(), '100%', '100%', '0px', '0px', null, null);
			}).fail(function (error) {
				console.log(error);
			});
			return false;
		});




		//弹出页面关闭后为控件赋值 无弹出页面可删除
		$("#Pu_value").click(function () {
			mySelf.getValueFromPopUp();//控件赋值
			readValue();//执行数据读取
		});

		//数据读取
		function readValue() {
			var _gridList = [];
			mySelf.getSelectGridTable(_gridList, $('#Pu_tbid').val(), $('#Pu_id').val());

			var _controlsList = [];
			$.each($("form").serializeArray(), function (i, field) {
				_controlsList.push({ ControlID: field.name, ControlValue: field.value });
			  /*  alert(field.name + ":" + field.value);*/
			});
			//还要将禁用的控件push

			exUtils.ajax("/Demo05/AfterControlSelect", "post", { controlslist: _controlsList, "gridlist": _gridList, id: $('#Pu_id').val(), tbid: $('#Pu_tbid').val(), indexid: $('#Pu_indexid').val(), value: $('#Pu_value').val() }, true).done(function (response) {
				lists = response.list;
				console.log(lists);
				//使用后台返回的lists，为控件赋值
				mySelf.setValueByList(lists);

				form.render();//一定要加
			}).fail(function (error) {
				console.log(error);
			});

			return false;
		}

	});
</script>